package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.UserBean;

import com.project.mapper.IUserMapper;

import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserService implements IUserService {
    @Autowired
    private IUserMapper userDao;
    @Override
    public UserBean login(String username, String password) {
        QueryWrapper<UserBean> qw = new QueryWrapper<UserBean>();
        qw.eq("userName", username);
        qw.eq("password", password);
        UserBean user = userDao.selectOne(qw);
        return user;
    }
    @Override
    public IPage<UserBean> findAllUsers(int pageNO) {
        return userDao.selectPage(new Page(pageNO,3),null);
    }

    @Override
    public UserBean updateUserStatus(String userId, String status) {
        QueryWrapper<UserBean> qw = new QueryWrapper<>();
        qw.eq("userNum", userId);
        UserBean userBean = userDao.selectOne(qw);
        if (userBean != null){
            userBean.setStatus(status);
            userDao.updateById(userBean);
            return userBean;
        }
        return null;
    }
}
